/*
 *  ColladaToProtoBuffer.h
 *  ColladaToProtoBuffer
 *
 *  Created by Micah Pearlman on 12/11/08.
 *  Copyright 2008 Monk Games. All rights reserved.
 *
 */

#ifndef __ColladaToProtoBuffer_h__
#define __ColladaToProtoBuffer_h__

#include <conditionerBase.h>
#include <boost/functional/hash.hpp>
#include <dom/domCOLLADA.h>

// protobuf includes
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include "physics.pb.h"
#include "math_types.pb.h"

// convert strings into 32 bit hashes for quick look up
// BUGBUG: hash collisions are not checked!  It is possible to have a duplicate hash from different string sources!
inline size_t StringHash( const std::string &s )
{
	boost::hash< std::string > boost_string_hash;
	return boost_string_hash( s );
}

inline size_t StringHash( const char* s )
{
	return StringHash( std::string( s ) );
}


class ColladaToProtoBuffer : public ConditionerBase {
	
public: 
	
	ColladaToProtoBuffer() 
	:	dom_( 0 )
	{};
	
	virtual ~ColladaToProtoBuffer() {};
	
	REF_EXPORT bool init();
	REF_EXPORT int execute();
	
	REF_EXPORT std::string getBaseName() const { return "ColladaToProtoBuffer"; }
	REF_EXPORT std::string getDescription() const { return "Descriptive information of MyConditioner."; }
	REF_EXPORT std::string getCategory() const  { return "Misc."; }
	
private: 
	
	bool ProcessPhysicsMaterials();
	bool ProcessRigidBodies();
	bool ProcessConstraints();
	bool ProcessPhysicsModels();
	bool ProcessPhysicsScenes();
	
private:

	domCOLLADA*	dom_;
	::collada_to_protobuf::library_physics_materials	physics_material_library_;
	::collada_to_protobuf::library_physics_models		physics_model_library_;
	::collada_to_protobuf::library_physics_scenes		physics_scene_library_;
	
};

class MyConditionerProxy : public ConditionerCreator
	{
		REF_EXPORT std::string getBaseName() const { return "ColladaToProtoBuffer"; }
		REF_EXPORT std::string getDescription() const { return "Descriptive information of MyConditioner."; }
		REF_EXPORT std::string getCategory() const  { return "Misc."; }
		
		REF_EXPORT Conditioner *create() const { return new ColladaToProtoBuffer(); }
	};
	
#endif